package com.zeedev.flyingsaucer.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import mobi.zeedev.flyingsaucer.common.DataModule.MetaBeer.DB_TYPES;

import java.util.HashMap;

public abstract class BeerDataHelperBase extends SQLiteOpenHelper {
	
	public static final String TAG = "BeerDataHelperBase";
	
	public BeerDataHelperBase(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
	}
	
	public static final String genericCreateCommand(String tableNameIn, String[] PROPERTIES_LIST,
			DB_TYPES[] TYPES_LIST) {
				StringBuilder sb = new StringBuilder();
				sb.append("CREATE TABLE " + tableNameIn + " (");
				for (int i = 0; i < PROPERTIES_LIST.length; i++) {
					sb.append(PROPERTIES_LIST[i] + " " + BeerDataHelperBase.typeToSQL.get(TYPES_LIST[i]));
					if (i != PROPERTIES_LIST.length-1) {
						sb.append(",");
					}
				}
				sb.append(");");
				//Log.d(TAG,"Create command: " + sb.toString());
				return sb.toString();
			}

	public static HashMap<DB_TYPES, String> typeToSQL = null;
	
	static {
		typeToSQL = new HashMap<DB_TYPES,String>();	
		typeToSQL.put(DB_TYPES.DB_INTEGER, "INTEGER");
		typeToSQL.put(DB_TYPES.DB_STRING, "TEXT" );
		typeToSQL.put(DB_TYPES.DB_DATE, "INTEGER");
		typeToSQL.put(DB_TYPES.DB_BOOLEAN, "BOOLEAN");
		typeToSQL.put(DB_TYPES.DB_KEY, "INTEGER PRIMARY KEY");
		//INTEGER PRIMARY PRIMARY_KEY AUTOINCREMENT
		typeToSQL.put(DB_TYPES.DB_KEY_AUTO, "INTEGER PRIMARY KEY AUTOINCREMENT");
	}

}